# -*- coding: utf8 -*-
import re

code = r"\{{2}\s+([a-zA-Z])+\s+\}{2}"

pattern = re.compile(code)

text = "My name is {{ name }} and I am forever {{ age }}."


def parse_string(text, value):
    groups = pattern.finditer(text)
    start = 0
    for g in groups:
        # print("start, end", g.start(), g.end())
        # print("pos, endpos", g.pos, g.endpos)
        # print("group", g.group())
        print("start", text[start:g.start()])
        start = g.end()
        print("end", text[start:], '')


# def get_chucks(text):
#     """
#     get_chucks('aa #{a} bb') -> [('aa ', '#{a}'), (' bb', '')]
#     """
#     matchs = pattern.finditer(text)
#     pos = 0
#     for match in matchs:
#         print(text[pos:match.start()], match.group(1))
#         pos = match.end()
#     print(text[pos:], '')

# get_chucks(a)
parse_string(text, None)